<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" size="mini">
      <el-form-item label="题库名">
        <el-input v-model="form.topicBankName"></el-input>
      </el-form-item>
      <el-form-item label="题库描述">
        <el-input v-model="form.topicBankDescription"></el-input>
      </el-form-item>
      <el-form-item label="题库标签">
<!--        <el-input v-model="form.topicBankLabel"></el-input>-->
        <el-select v-model="form.topicBankLabel" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            {{item.label}}
         </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="save">保存数据</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "@/utils/axiosutils.js"


export default {
  name: "edit",
  props: ['editid'],
  data() {
    return {
      form: {
        id:null,
        topicBankName:"",
        topicBankTopics:"",
        topicBankLabel:"",
        topicBankDescription:'',
        choiceNumber:0,
        blankNumber:0,
        judgeNumber:0,
        shortAnswerNumber:0,
        totalNumber:0,
        creator:"",
        createtime:null,
        isDelete:null,
      },
      options: [{
        value: 'Java',
        label: 'Java'
      }, {
        value: 'Python',
        label: 'Python'
      }, {
        value: 'Html',
        label: 'Html'
      }],
    };
  },
  created() {
    if (this.editid) {
      axios.get(
          '/topicBank/getById',
          response => {
            this.form.id = response.obj.id;
            this.form.topicBankName = response.obj.topicBankName;
            this.form.topicBankTopics = response.obj.topicBankTopics;
            this.form.topicBankDescription = response.obj.topicBankDescription;
            this.form.topicBankLabel = response.obj.topicBankLabel;
            this.form.choiceNumber = response.obj.choiceNumber;
            this.form.blankNumber = response.obj.blankNumber;
            this.form.judgeNumber = response.obj.judgeNumber;
            this.form.shortAnswerNumber = response.obj.shortAnswerNumber;
            this.form.totalNumber = response.obj.totalNumber;
            this.form.creator = response.obj.creator;
            this.form.createtime = response.obj.createtime;
            this.form.isDelete = response.obj.isDelete;
          }, {
            id: this.editid
          }
      );
    }
  },
  methods: {
    save: function () {
      axios.post(
          '/topicBank/saveOrUpdate',
          resp => {
            this.$emit('update:show', false);
            this.$emit('getData');
          },
          this.form
      );
    }
  }
};
</script>

<style></style>